import { Entity, Column, PrimaryGeneratedColumn, OneToMany, JoinColumn, ManyToOne } from 'typeorm';
import { ApiProperty} from '@nestjs/swagger';
import { IsOptional } from 'class-validator';
import { Goods } from './goods.entity';
import { OrderGoods } from './order_goods.entities';
import { Collect } from './collect.entity';

@Entity()
export class Product {
  @PrimaryGeneratedColumn({type: 'mediumint'})
  id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'mediumint' })
  goods_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 50 })
  goods_specification_ids: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 60 })
  goods_sn: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'mediumint' })
  goods_number: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', width: 10, precision:2 })
  retail_price: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'decimal', width: 10, precision:2 })
  market_price: number;

  @ManyToOne(type => Goods,goods => goods.product)
  @JoinColumn({
    name:"goods_id"
  })
  goods:Goods

  @OneToMany(type => OrderGoods,orderGoods => orderGoods.product)
  orderGoods:OrderGoods[]

  @OneToMany(type => Collect,collect => collect.product)
  collect:Collect[]
}
